const postcss = require("postcss");
const CONFIG = require("./config.json");
const OPTIONS = require("./config");

module.exports = postcss.plugin("tailwind-one", (opts = {}) => root => {
    const _opts = {...OPTIONS, ...opts};
    const _platform = _opts.platform;
    const _config = CONFIG[_platform];

    if (_opts.debug) {
        console.log(`[tailwind-one] 平台:${_platform} 传入配置:${JSON.stringify(opts)}`)
    }

    require(`./walkrule.${_platform}`)(_config, root, _opts);
    require("./unit")(root, _opts);
});


// // for postcss 8
// module.exports = (opts = {}) => {
//     const _opts = {...OPTIONS, ...opts};
//     const _platform = _opts.platform;
//     const _config = CONFIG[_platform];
//     return {
//         postcssPlugin: "tailwind-one",
//         Once(root) {
//             require(`./walkrule.${_platform}`)(_config, root, _opts);
//             require("./unit")(root, _opts);
//         }
//     }
// }
//
// module.exports.postcss = true